//
//  MoviePlayerViewController.m
//  e-Learning
//
//  Created by rimi on 16/6/23.
//  Copyright © 2016年 YJ. All rights reserved.
//

#import "MoviePlayerViewController.h"
#import "PlayerView.h"
#import "InfoTableViewCell.h"
#import "QuestionTableViewCell.h"
#import "FriendInfoTableViewCell.h"
#import "DetailInfoTableViewCell.h"

@interface MoviePlayerViewController ()<UIAlertViewDelegate,UITableViewDataSource,UITableViewDelegate>
{
    NSArray *rightToolBtnNames;
    NSMutableArray *bottomBtnArray;
    int currentBottomBtnIndex;
    UIView *lessonVu;
    UIButton *clearBtn;
    BOOL isShowRightTool;
    AVPlayerItem *playerItem;
    int playIndex;
    UILabel *titleLabel;
    NSArray *customBtnNames;
    NSMutableArray *interactionArray;
    NSMutableArray *rightDataSource;
    UITableView *interationTableVu;
    UITableView *rightTableVu;
    UIView *containerVu;
    int currentPageNum;
    int currentTableViewIndex;
    int pageCount;
    UITextView *noteText;
    int currentRightIndex;
    UIView *detailContainerVu;
    UIView *friendContainerVu;
    NSArray *detailInfoArray;
}
@property (nonatomic,strong) UIView *rightTool;
@property (nonatomic,strong) UIView *bottomTool;
@property (nonatomic,strong) UILabel *timeLabel;
@property (nonatomic,strong) UISlider *slider;
@property (nonatomic,strong) UIButton *playerBtn;
@property (nonatomic,strong) NSDateFormatter *dateFormatter;
@property (nonatomic,strong) NSString *totalTime;
@property (nonatomic,strong) PlayerView *playerView;
@property (nonatomic,strong) id playbackTimeObserver;

@end

@implementation MoviePlayerViewController


#pragma mark - LifeCycle
- (void)dealloc{
   NSLog(@"%@",NSStringFromSelector(_cmd));
    [playerItem removeObserver:self forKeyPath:@"status" context:nil];
    [self.playerView.player removeTimeObserver:self.playbackTimeObserver];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blackColor];
    [self initializeDataSource];
    [self loadUI];
    [self video];
}

- (void)viewWillDisappear:(BOOL)animated{
    [lessonVu removeFromSuperview];
    lessonVu = nil;
    [clearBtn removeFromSuperview];
    clearBtn = nil;
    [containerVu removeFromSuperview];
    containerVu = nil;
    [self.rightTool removeFromSuperview];
    self.rightTool = nil;
    [self.bottomTool removeFromSuperview];
    self.bottomTool = nil;
    [self.playerView removeFromSuperview];
    self.playerView = nil;
    [playerItem removeObserver:self forKeyPath:@"status" context:nil];
    [self.playerView.player removeTimeObserver:self.playbackTimeObserver];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark - Initialize

- (void)initializeDataSource{
    rightToolBtnNames = @[@"下载",@"收藏",@"评分",@"学友资料",@"我的笔记",@"我的问答",@"分享"];
    customBtnNames = @[@"",@"互动",@"提问",@"记笔记",@"",@"",@"",@"",@"",@"",@"下载",@"收藏",@"评分",@"学友资料",@"我的笔记",@"我的回答",@"分享"];
    currentBottomBtnIndex = -1;
    bottomBtnArray = [@[] mutableCopy];
    isShowRightTool = YES;
    playIndex = 0;
    currentPageNum = 0;
    interactionArray = [@[] mutableCopy];
    currentTableViewIndex = 0;
    currentRightIndex = 0;
    rightDataSource = [@[] mutableCopy];
    pageCount = 0;
}

- (void)loadUI{
    //布置界面
    [self.view addSubview:self.bottomTool];
    [self.view addSubview:self.rightTool];
    
    
    UIButton *showOrHiddenRightTool = [[UIButton alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [showOrHiddenRightTool addTarget:self action:@selector(showOrHiddenRightTool) forControlEvents:UIControlEventTouchUpInside];
    [self.view insertSubview:showOrHiddenRightTool belowSubview:self.bottomTool];
    
    UIView *playerBackgroundVu = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width/3*2, Screen_Height/8)];
    playerBackgroundVu.backgroundColor = [UIColor colorWithRed:56/255.0 green:56/255.0 blue:56/255.0 alpha:1];
    [self.bottomTool addSubview:playerBackgroundVu];
    
    
    self.playerBtn = [[UIButton alloc] initWithFrame:CGRectMake(Screen_Height/8/3/2, Screen_Height/8/3, Screen_Height/8/3, Screen_Height/8/3)];
    [self.playerBtn setBackgroundImage:[UIImage imageNamed:@"lesson_play.png"] forState:UIControlStateNormal];
    [self.playerBtn setBackgroundImage:[UIImage imageNamed:@"lesson_pause.png"] forState:UIControlStateSelected];
    [self.playerBtn addTarget:self action:@selector(tapPlayerBtn:) forControlEvents:UIControlEventTouchUpInside];
    self.playerBtn.enabled = NO;
    [playerBackgroundVu addSubview:self.playerBtn];
    [playerBackgroundVu addSubview:self.timeLabel];
    
    UILabel *status = [[UILabel alloc] initWithFrame:CGRectMake(Screen_Width/3*2/3*2, Screen_Height/8*0.7, Screen_Width/3*2/3-Screen_Width/3*2/30, Screen_Height/8/3)];
    status.text = @"读取状态中";
    status.textColor = [UIColor whiteColor];
    status.textAlignment = NSTextAlignmentRight;
    status.font = [UIFont systemFontOfSize:20];
    [playerBackgroundVu addSubview:status];
    self.slider = [[UISlider alloc] initWithFrame:CGRectMake(Screen_Height/8/3+Screen_Height/8/3, Screen_Height/8/3, Screen_Width/3*2*0.88, Screen_Height/8/3)];
    [playerBackgroundVu addSubview:self.slider];
    
    for (int i = 0 ; i < 5; i ++) {
        CustomBtn *btn = [[CustomBtn alloc] initWithFrame:CGRectMake(Screen_Width/3*2+i*Screen_Width/3/5, (Screen_Height/8-Screen_Width/3/5)/2, Screen_Width/3/5, Screen_Width/3/5) index:i];
        [btn setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"boadcast_button%d.png",i+1]] forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"boadcast_button%d_s.png",i+1]] forState:UIControlStateSelected];
        [btn addTarget:self action:@selector(ToolBtn:) forControlEvents:UIControlEventTouchUpInside];
        [bottomBtnArray addObject:btn];
        [self.bottomTool addSubview:btn];
    }
    
    for (int i = 0 ; i < rightToolBtnNames.count; i ++) {
        CustomBtn *btn = [[CustomBtn alloc] initWithFrame:CGRectMake(0, i*Screen_Height/2/rightToolBtnNames.count, Screen_Width/8, Screen_Height/2/rightToolBtnNames.count) index:10+i];
        btn.layer.borderColor = [UIColor lightGrayColor].CGColor;
        btn.layer.borderWidth = 0.75;
        [btn setTitle:rightToolBtnNames[i] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor cyanColor] forState:UIControlStateHighlighted];
        btn.titleLabel.textAlignment = NSTextAlignmentNatural;
        [btn addTarget:self action:@selector(ToolBtn:) forControlEvents:UIControlEventTouchUpInside];
        [self.rightTool addSubview:btn];
    }
}

#pragma mark - ActionEvents

#pragma mark 下面为视频块
- (void)video{
    self.playerView = [[PlayerView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width, Screen_Height/8*7)];
    [self.view insertSubview:self.playerView atIndex:0];
    playerItem = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:self.playerListArray[playIndex]]];
    [playerItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil];
    self.playerView.player = [AVPlayer playerWithPlayerItem:playerItem];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem];
    
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context{
    AVPlayerItem *item = (AVPlayerItem *)object;
    if ([keyPath isEqualToString:@"status"]) {
        //状态改变,初始化播放状态
        self.playerBtn.enabled = YES;
        CMTime duration = playerItem.duration;// 获取视频总长度
        CGFloat totalSecond = item.duration.value / item.duration.timescale;// 转换成秒
        self.totalTime = [self convertTime:totalSecond];// 转换成播放时间
        [self dealSlider:duration];//处理slider
        [self monitoringPlay:playerItem];// 监听播放状态
        [self.playerView.player play];
        self.playerBtn.selected = YES;
    }
}

- (NSString *)convertTime:(CGFloat)second{
    NSDate *d = [NSDate dateWithTimeIntervalSince1970:second];
    if (second/3600 >= 1) {
        [[self dateFormatter] setDateFormat:@"HH:mm:ss"];
    } else {
        [[self dateFormatter] setDateFormat:@"mm:ss"];
    }
    NSString *showtimeNew = [[self dateFormatter] stringFromDate:d];
    return showtimeNew;
}

- (void)dealSlider:(CMTime)duration{
    //改slider
    self.slider.maximumValue = CMTimeGetSeconds(duration);
    [self.slider addTarget:self action:@selector(touchDown:) forControlEvents:UIControlEventTouchDown];
    [self.slider addTarget:self action:@selector(valueChange:) forControlEvents:UIControlEventValueChanged];
    [self.slider addTarget:self action:@selector(touchUp:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)touchUp:(UISlider *)slider{

    __weak typeof(self) weakSelf = self;
    [self.playerView.player seekToTime:CMTimeMake(slider.value, 1) completionHandler:^(BOOL finished) {
        [weakSelf.playerView.player play];
        weakSelf.playerBtn.selected = YES;
    }];
    
}
- (void)touchDown:(UISlider *)slider{
    [self.playerView.player pause];
    self.playerBtn.selected = NO;
}

- (void)valueChange:(UISlider *)slider{

    [self.playerView.player seekToTime:CMTimeMake(slider.value, 1)];
    CMTime currentTime = CMTimeMake(slider.value, 1);
       NSLog(@"当前%lld",currentTime.value / currentTime.timescale);
    if (self.playerView.player.currentTime.value / self.playerView.player.currentTime.timescale+1 == self.playerView.player.currentItem.duration.value / self.playerView.player.currentItem.duration.timescale-1) {
        [self.playerView.player seekToTime:kCMTimeZero completionHandler:^(BOOL finished) {
            [self.slider setValue:0 animated:YES];
            self.playerBtn.selected = NO;
        }];
    }
}



- (void)monitoringPlay:(AVPlayerItem *)playItem{
    __weak typeof(self) weakSelf = self;
    self.playbackTimeObserver = [self.playerView.player addPeriodicTimeObserverForInterval:CMTimeMake(1, 10) queue:NULL usingBlock:^(CMTime time) {
//         NSLog(@"----当前%f",self.playerView.player.currentTime.value / (self.playerView.player.currentTime.timescale/1.0) );
        CGFloat currentSecond = playerItem.currentTime.value /(playerItem.currentTime.timescale/1.0);// 计算当前在第几秒
        [weakSelf.slider setValue:currentSecond animated:YES];
        NSString *timeString = [weakSelf convertTime:currentSecond];
        weakSelf.timeLabel.text = [NSString stringWithFormat:@"%@/%@",timeString,weakSelf.totalTime];
    }];
}

- (void)playerEnd:(NSNotification *)notification{
    //当前视频播放完成
    if (playIndex < self.playerListArray.count-1) {
        //还有视频可播
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"是否进入下一课程" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        alert.tag = 200;
        [alert show];
    } else {
        //没视频了
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"当前没有课程了\n是否退出播放器" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        alert.tag = 201;
        [alert show];
    }
}

#pragma mark  上面为视频块
#pragma mark -


- (void)showOrHiddenRightTool{
    //右边工具栏动画
    if (isShowRightTool) {
        [UIView animateWithDuration:0.3 animations:^{
           self.rightTool.frame = CGRectMake(Screen_Width, Screen_Height/2/2, Screen_Width/8, Screen_Height/2);
        } completion:^(BOOL finished) {
            isShowRightTool = NO;
        }];
    } else {
        [UIView animateWithDuration:0.3 animations:^{
            self.rightTool.frame = CGRectMake(Screen_Width/8*7, Screen_Height/2/2, Screen_Width/8, Screen_Height/2);
        } completion:^(BOOL finished) {
            isShowRightTool = YES;
        }];
    }
}


- (void)tapPlayerBtn:(UIButton *)sender{
    //播放暂时操作
    sender.selected = !sender.selected;
    if (sender.selected) {
        [self.playerView.player play];
    } else {
        [self.playerView.player pause];
    }
}

- (void)ToolBtn:(CustomBtn *)sender{
    if (sender.index >= 0 && sender.index <= 4) {
        //下面按钮
        for (int i = 0 ; i < 5; i ++) {
            CustomBtn *btn = bottomBtnArray[i];
            btn.userInteractionEnabled = NO;
        }
        if (currentBottomBtnIndex == sender.index) {
            //重复选中
            for (int i = 0 ; i < 5; i ++) {
                CustomBtn *btn = bottomBtnArray[i];
                btn.userInteractionEnabled = YES;
            }
            if (sender.index != 4) {
                return;
            }
        }
        //按钮处理
        if (currentBottomBtnIndex == -1) {
            //第一次选中
            sender.selected = YES;
            currentBottomBtnIndex = sender.index;
        } else {
            CustomBtn *beforeBtn = bottomBtnArray[currentBottomBtnIndex];
            beforeBtn.selected = NO;
            sender.selected = YES;
            currentBottomBtnIndex = sender.index;
        }
        //事件处理
        switch (sender.index) {
            case 0: [self lessonContents]; break;
            case 1: [self interaction]; break;
            case 2: [self question]; break;
            case 3: [self rememberNote]; break;
            case 4: [self back];break;
            default:break;
        }
    } else if (sender.index >= 10 && sender.index <= 16){
        //右边按钮
        switch (sender.index) {
            case 10: [self download];break;
            case 11: [self collect];break;
            case 12: [self evaluate];break;
            case 13: [self frinedInfo];break;
            case 14: [self myNote];break;
            case 15: [self myAnswer];break;
            case 16: [self share];break;
            default:break;
        }
    }
}

- (void)createContainerVu {
    containerVu = [[UIView alloc] initWithFrame:CGRectMake(Screen_Width, 0, Screen_Width/3, Screen_Height/8*7)];
    containerVu.backgroundColor = [UIColor darkGrayColor];
    UIView *headerVu = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width/3, Screen_Height/8*7*0.1)];
    headerVu.backgroundColor = [UIColor darkGrayColor];
    [containerVu addSubview:headerVu];
    titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, Screen_Width/3, Screen_Height/8*7*0.1)];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = [UIFont boldSystemFontOfSize:23];
    titleLabel.textColor = [UIColor whiteColor];
    [containerVu addSubview:titleLabel];
    UIButton *rightToolBackBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, Screen_Height/8*7*0.1, Screen_Height/8*7*0.1)];
    [rightToolBackBtn addTarget:self action:@selector(rightToolBtn:) forControlEvents:UIControlEventTouchUpInside];
    [rightToolBackBtn setBackgroundImage:[UIImage imageNamed:@"video_interaction_back.png"] forState:UIControlStateNormal];
    [containerVu addSubview:rightToolBackBtn];
    [self.view addSubview:containerVu];
}

- (void)rightToolBtn:(UIButton *)sender{
    currentTableViewIndex = 0;
    sender.enabled = NO;
    [UIView animateWithDuration:0.5 animations:^{
        containerVu.frame = CGRectMake(Screen_Width, 0, Screen_Width, Screen_Height/8*7);
        self.playerView.frame = CGRectMake(0, 0, Screen_Width, Screen_Height/8*7);
    } completion:^(BOOL finished) {
        for (int i = 0 ; i < 5; i ++) {
            CustomBtn *btn = bottomBtnArray[i];
            btn.userInteractionEnabled = YES;
        }
        CustomBtn *btn = bottomBtnArray[currentBottomBtnIndex];
        btn.selected = NO;
        btn = nil;
        currentBottomBtnIndex = -1;
        [containerVu removeFromSuperview];
        containerVu = nil;
        [interactionArray removeAllObjects];
    }];
}

- (void)createRightBtnContainerVu {
    containerVu = [[UIView alloc] initWithFrame:CGRectMake(Screen_Width, 0, Screen_Width/3, Screen_Height/8*7)];
    containerVu.backgroundColor = [UIColor darkGrayColor];
    UIView *headerVu = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width/3, Screen_Height/8*7*0.1)];
    headerVu.backgroundColor = [UIColor darkGrayColor];
    [containerVu addSubview:headerVu];
    titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, Screen_Width/3, Screen_Height/8*7*0.1)];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = [UIFont boldSystemFontOfSize:23];
    titleLabel.textColor = [UIColor whiteColor];
    [containerVu addSubview:titleLabel];
    UIButton *rightToolBackBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, Screen_Height/8*7*0.1, Screen_Height/8*7*0.1)];
    [rightToolBackBtn addTarget:self action:@selector(rightBackBtn:) forControlEvents:UIControlEventTouchUpInside];
    [rightToolBackBtn setBackgroundImage:[UIImage imageNamed:@"video_interaction_back.png"] forState:UIControlStateNormal];
    [containerVu addSubview:rightToolBackBtn];
    [self.view addSubview:containerVu];
}

- (void)rightBackBtn:(UIButton *)sender{
    sender.enabled = NO;
    [UIView animateWithDuration:0.5 animations:^{
        containerVu.frame = CGRectMake(Screen_Width, 0, Screen_Width, Screen_Height/8*7);
        self.playerView.frame = CGRectMake(0, 0, Screen_Width, Screen_Height/8*7);
    } completion:^(BOOL finished) {
        sender.enabled = YES;
        [containerVu removeFromSuperview];
        containerVu = nil;
        [rightDataSource removeAllObjects];
    }];
}

- (void)detailBackBtn:(UIButton *)sender{
    [UIView animateWithDuration:0.3 animations:^{
        friendContainerVu.frame = CGRectMake(0, 0, Screen_Width/3, Screen_Height/8*7);
        detailContainerVu.frame = CGRectMake(Screen_Width/3, 0, Screen_Width/3, Screen_Height/8*7);
    } completion:^(BOOL finished) {
        [detailContainerVu removeFromSuperview];
        detailContainerVu = nil;
    }];
}

- (void)dealData:(NSString *)urlString{
    [interactionArray removeAllObjects];
    [self createContainerVu];
    titleLabel.text = customBtnNames[currentBottomBtnIndex];
    
    UIView *bottomVu = [[UIView alloc] initWithFrame:CGRectMake(0, Screen_Height/8*7*0.9, Screen_Width/3, Screen_Height/8*7*0.1)];
    bottomVu.backgroundColor = [UIColor colorWithRed:56/255.0 green:56/255.0 blue:56/255.0 alpha:1];
    [containerVu addSubview:bottomVu];
    UITextField *text = [[UITextField alloc] initWithFrame:CGRectMake(Screen_Width/3*0.05,Screen_Height/8*7*0.1*0.2,Screen_Width/3*0.7,Screen_Height/8*7*0.1*0.6)];
    text.backgroundColor = [UIColor whiteColor];
    [bottomVu addSubview:text];
    UIButton *sendBtn = [[UIButton alloc] initWithFrame:CGRectMake(Screen_Width/3*0.75, Screen_Height/8*7*0.1*0.05, Screen_Width/3*0.2, Screen_Width/3*0.2)];
    [sendBtn setBackgroundImage:[UIImage imageNamed:@"i_lg_未连接_03.png"] forState:UIControlStateNormal];
    [bottomVu addSubview:sendBtn];
    
    interationTableVu = [[UITableView alloc] initWithFrame:CGRectMake(0, Screen_Height/8*7*0.1, Screen_Width/3, Screen_Height/8*7*0.8) style:UITableViewStylePlain];
    [interationTableVu registerClass:[InfoTableViewCell class] forCellReuseIdentifier:@"info"];
    [interationTableVu registerClass:[QuestionTableViewCell class] forCellReuseIdentifier:@"question"];
    interationTableVu.tableFooterView = [UIView new];
    interationTableVu.dataSource = self;
    interationTableVu.delegate = self;
    interationTableVu.tag = 300;
    interationTableVu.backgroundColor = [UIColor colorWithRed:56/255.0 green:56/255.0 blue:56/255.0 alpha:1];
    [containerVu addSubview:interationTableVu];
    if (currentTableViewIndex == 1) {
        interationTableVu.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
            [[NetWorkTools sharedTools] requestMethod:POST URL:sid(url(urlString)) parameters:@{@"id":self.playerListIDArray[playIndex],@"pageNum":@(1),@"pagesize":@(10)} finish:^(id responseObject, NSError *error) {
                if ([responseObject[@"status"] intValue] == 104) {
                    NSLog(@"重复登陆");
                } else if ([responseObject[@"status"] intValue] == 1) {
                    [interactionArray addObjectsFromArray:responseObject[@"data"]];
                    currentPageNum = 1;
                    [interationTableVu reloadData];
                    [interationTableVu.mj_header endRefreshing];
                }
            }];
        }];
        [interationTableVu.mj_header beginRefreshing];
        interationTableVu.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
            currentPageNum = (int)interactionArray.count/10;
            currentPageNum ++;
            if (interactionArray.count/10 == 0) {
                [interationTableVu.mj_footer endRefreshing];
                return ;
            }
            [[NetWorkTools sharedTools] requestMethod:POST URL:sid(url(urlString)) parameters:@{@"id":self.playerListIDArray[playIndex],@"pageNum":@(currentPageNum),@"pagesize":@(10)} finish:^(id responseObject, NSError *error) {
                if ([responseObject[@"status"] intValue] == 104) {
                    NSLog(@"重复登陆");
                } else if ([responseObject[@"status"] intValue] == 1) {
                    if (currentPageNum > [responseObject[@"pageCount"] intValue]) {
                        [interationTableVu.mj_footer endRefreshing];
                        currentPageNum = [responseObject[@"pageCount"] intValue];
                    } else {
                        [interactionArray addObjectsFromArray:responseObject[@"data"]];
                        [interationTableVu reloadData];
                        [interationTableVu.mj_footer endRefreshing];
                    }
                }
            }];
        }];
    } else {
        interationTableVu.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
            [[NetWorkTools sharedTools] requestMethod:POST URL:sid(url(urlString)) parameters:@{@"id":self.playerListIDArray[playIndex],@"myself":@(0),@"pageNum":@(1),@"pagesize":@(10)} finish:^(id responseObject, NSError *error) {
                if ([responseObject[@"status"] intValue] == 104) {
                    NSLog(@"重复登陆");
                } else if ([responseObject[@"status"] intValue] == 1) {
                    [interactionArray removeAllObjects];
                    [interactionArray addObjectsFromArray:responseObject[@"data"]];
                    currentPageNum = 1;
                    [interationTableVu reloadData];
                    [interationTableVu.mj_header endRefreshing];
                } else {
                    [interationTableVu.mj_header endRefreshing];
                }
            }];
        }];
        [interationTableVu.mj_header beginRefreshing];
        interationTableVu.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
            currentPageNum = (int)interactionArray.count/10;
            currentPageNum ++;
            if (interactionArray.count/10 == 0) {
                [interationTableVu.mj_footer endRefreshing];
                return ;
            }
            [[NetWorkTools sharedTools] requestMethod:POST URL:sid(url(urlString)) parameters:@{@"id":self.playerListIDArray[playIndex],@"myself":@(0),@"pageNum":@(currentPageNum),@"pagesize":@(10)} finish:^(id responseObject, NSError *error) {
                if ([responseObject[@"status"] intValue] == 104) {
                    NSLog(@"重复登陆");
                } else if ([responseObject[@"status"] intValue] == 1) {
                    if (currentPageNum > [responseObject[@"pageCount"] intValue]) {
                        [interationTableVu.mj_footer endRefreshing];
                        currentPageNum = [responseObject[@"pageCount"] intValue];
                    } else {
                        [interactionArray addObjectsFromArray:responseObject[@"data"]];
                        [interationTableVu reloadData];
                        [interationTableVu.mj_footer endRefreshing];
                    }
                } else {
                    [interationTableVu.mj_footer endRefreshing];
                }
            }];
        }];
    }
    
    [UIView animateWithDuration:0.5 animations:^{
        containerVu.frame = CGRectMake(Screen_Width/3*2, 0, Screen_Width, Screen_Height/8*7);
    } completion:^(BOOL finished) {
        for (int i = 0 ; i < 5; i ++) {
            CustomBtn *btn = bottomBtnArray[i];
            btn.userInteractionEnabled = YES;
        }
    }];
}

- (void)dealRightData:(NSString *)url{
    [rightDataSource removeAllObjects];
    [self createRightBtnContainerVu];
    titleLabel.text = customBtnNames[currentRightIndex];
    
    if (currentRightIndex == 10 || currentRightIndex == 14 || currentRightIndex == 15) {
        rightTableVu = [[UITableView alloc] initWithFrame:CGRectMake(0, Screen_Height/8*7*0.1, Screen_Width/3, Screen_Height/8*7*0.9) style:UITableViewStylePlain];
        rightTableVu.tableFooterView = [UIView new];
        rightTableVu.backgroundColor = [UIColor colorWithRed:42/255.0 green:42/255.0 blue:42/255.0 alpha:1];
        rightTableVu.dataSource = self;
        rightTableVu.delegate = self;
        rightTableVu.tag = 301;
        [rightTableVu registerClass:[FriendInfoTableViewCell class] forCellReuseIdentifier:@"friendInfo"];
        [containerVu addSubview:rightTableVu];
    }
    if (currentRightIndex == 12 || currentRightIndex == 16) {
        UIView *backgroundVu = [[UIView alloc] initWithFrame:CGRectMake(0, Screen_Height/8*7*0.1, Screen_Width/3, Screen_Height/8*7*0.9)];
        backgroundVu.backgroundColor = [UIColor colorWithRed:42/255.0 green:42/255.0 blue:42/255.0 alpha:1];
        [containerVu addSubview:backgroundVu];
    }
    
    
    if (currentRightIndex == 10) {
        //下载
        [[NetWorkTools sharedTools] requestMethod:POST URL:sid(url(url)) parameters:@{@"token":[[NSUserDefaults standardUserDefaults] objectForKey:@"token"]} finish:^(id responseObject, NSError *error) {
            
        }];
    } else if (currentRightIndex == 12){
        //评分
        
    } else if (currentRightIndex == 13){
        //学友资料
        friendContainerVu = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width/3, Screen_Height/8*7)];
        friendContainerVu.backgroundColor = [UIColor darkGrayColor];
        UIView *headerVu = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width/3, Screen_Height/8*7*0.1)];
        headerVu.backgroundColor = [UIColor darkGrayColor];
        [friendContainerVu addSubview:headerVu];
        titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, Screen_Width/3, Screen_Height/8*7*0.1)];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.font = [UIFont boldSystemFontOfSize:23];
        titleLabel.textColor = [UIColor whiteColor];
        titleLabel.text = customBtnNames[currentRightIndex];
        [friendContainerVu addSubview:titleLabel];
        UIButton *rightToolBackBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, Screen_Height/8*7*0.1, Screen_Height/8*7*0.1)];
        [rightToolBackBtn addTarget:self action:@selector(rightBackBtn:) forControlEvents:UIControlEventTouchUpInside];
        [rightToolBackBtn setBackgroundImage:[UIImage imageNamed:@"video_interaction_back.png"] forState:UIControlStateNormal];
        [friendContainerVu addSubview:rightToolBackBtn];
        containerVu.clipsToBounds = YES;
        [containerVu addSubview:friendContainerVu];
        
        rightTableVu = [[UITableView alloc] initWithFrame:CGRectMake(0, Screen_Height/8*7*0.1, Screen_Width/3, Screen_Height/8*7*0.9) style:UITableViewStylePlain];
        rightTableVu.tableFooterView = [UIView new];
        rightTableVu.backgroundColor = [UIColor colorWithRed:42/255.0 green:42/255.0 blue:42/255.0 alpha:1];
        rightTableVu.dataSource = self;
        rightTableVu.delegate = self;
        rightTableVu.tag = 301;
        [rightTableVu registerClass:[FriendInfoTableViewCell class] forCellReuseIdentifier:@"friendInfo"];
        [friendContainerVu addSubview:rightTableVu];
        currentPageNum = 1;
        rightTableVu.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
            [[NetWorkTools sharedTools] requestMethod:POST URL:sid(url(url)) parameters:@{@"token":[[NSUserDefaults standardUserDefaults] objectForKey:@"token"],@"id":self.lessonID,@"numPerPage":@(10),@"pageNum":@(1)} finish:^(id responseObject, NSError *error) {
                if ([responseObject[@"status"] intValue] == 104) {
                    NSLog(@"重复登陆");
                } else if ([responseObject[@"status"] intValue] == 1){
                    
                    [rightDataSource addObjectsFromArray:responseObject[@"data"]];
                    pageCount = [responseObject[@"pageCount"] intValue];
                    [rightTableVu reloadData];
                    [rightTableVu.mj_header endRefreshing];
                }
            }];
        }];
        [rightTableVu.mj_header beginRefreshing];
        rightTableVu.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
            currentPageNum ++;
            if (currentPageNum>pageCount) {
                [rightTableVu.mj_footer endRefreshing];
                return ;
            }
            [[NetWorkTools sharedTools] requestMethod:POST URL:sid(url(url)) parameters:@{@"token":[[NSUserDefaults standardUserDefaults] objectForKey:@"token"],@"id":self.lessonID,@"numPerPage":@(10),@"pageNum":@(currentPageNum)} finish:^(id responseObject, NSError *error) {
                if ([responseObject[@"status"] intValue] == 104) {
                    NSLog(@"重复登陆");
                } else if ([responseObject[@"status"] intValue] == 1){
                    [rightDataSource addObjectsFromArray:responseObject[@"data"]];
                    [rightTableVu reloadData];
                    [rightTableVu.mj_footer endRefreshing];
                }
            }];
        }];
        
      
    } else if (currentRightIndex == 14){
        //我的笔记
       
        [[NetWorkTools sharedTools] requestMethod:POST URL:sid(url(url)) parameters:@{@"token":[[NSUserDefaults standardUserDefaults] objectForKey:@"token"],@"pageNum":@(1),@"pageSize":@(10),@"uid":[[NSUserDefaults standardUserDefaults] objectForKey:@"uid"]} finish:^(id responseObject, NSError *error) {
            
            NSLog(@"%@",responseObject);
        }];
    } else if (currentRightIndex == 15){
        //我的问答

    } else if (currentRightIndex == 16){
        //分享

    }
    
    
    [UIView animateWithDuration:0.5 animations:^{
        containerVu.frame = CGRectMake(Screen_Width/3*2, 0, Screen_Width, Screen_Height/8*7);
    }];
    
    
}


#pragma mark 😡😡😡😡😡😡😡😡😡😡😡😡右边按钮😡😡😡😡😡😡😡😡😡😡

- (void)download{
    currentRightIndex = 10;
    [UIView animateWithDuration:0.3 animations:^{
        self.playerView.frame = CGRectMake(0, 0, Screen_Width/3*2, Screen_Height*0.6);
    } completion:^(BOOL finished) {
        [self dealRightData:@""];
    }];
}

- (void)collect{
    currentRightIndex = 11;
    [[NetWorkTools sharedTools] requestMethod:POST URL:sid(url(@"front_video!addFavorite.action")) parameters:@{@"token":[[NSUserDefaults standardUserDefaults] objectForKey:@"token"],@"id":self.lessonID} finish:^(id responseObject, NSError *error) {
        if ([responseObject[@"status"] intValue] == 104) {
            NSLog(@"重复登陆");
        } else  if ([responseObject[@"status"] intValue] == -1) {
            //已收藏
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:responseObject[@"data"] preferredStyle:UIAlertControllerStyleAlert];
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                [alert dismissViewControllerAnimated:YES completion:nil];
            }]];
            [self presentViewController:alert animated:YES completion:nil];
        } else {
            //收藏成功
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"收藏成功" preferredStyle:UIAlertControllerStyleAlert];
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                [alert dismissViewControllerAnimated:YES completion:nil];
            }]];
            [self presentViewController:alert animated:YES completion:nil];
        }
    }];
}

- (void)evaluate{
    currentRightIndex = 12;
    [UIView animateWithDuration:0.3 animations:^{
        self.playerView.frame = CGRectMake(0, 0, Screen_Width/3*2, Screen_Height*0.6);
    } completion:^(BOOL finished) {
        [self dealRightData:@""];
    }];
}

- (void)frinedInfo{
    currentRightIndex = 13;
    [UIView animateWithDuration:0.3 animations:^{
        self.playerView.frame = CGRectMake(0, 0, Screen_Width/3*2, Screen_Height*0.6);
    } completion:^(BOOL finished) {
        [self dealRightData:@"front_video!courseUserList.action"];
    }];
}

- (void)myNote{
    currentRightIndex = 14;
    [UIView animateWithDuration:0.3 animations:^{
        self.playerView.frame = CGRectMake(0, 0, Screen_Width/3*2, Screen_Height*0.6);
    } completion:^(BOOL finished) {
        [self dealRightData:@"front_user_center!getMyNote.action"];
    }];
}

- (void)myAnswer{
    currentRightIndex = 15;
    [UIView animateWithDuration:0.3 animations:^{
        self.playerView.frame = CGRectMake(0, 0, Screen_Width/3*2, Screen_Height*0.6);
    } completion:^(BOOL finished) {
        [self dealRightData:@"front_user_center!questionHome.action"];
    }];
}


- (void)share{
    currentRightIndex = 16;
    [UIView animateWithDuration:0.3 animations:^{
        self.playerView.frame = CGRectMake(0, 0, Screen_Width/3*2, Screen_Height*0.6);
    } completion:^(BOOL finished) {
        [self dealRightData:@""];
    }];
}
#pragma mark 😡😡😡😡😡😡😡😡😡😡😡😡下面按钮😡😡😡😡😡😡😡😡😡😡
#pragma mark 课程

- (void)lessonContents{
    //收回右边
    if (containerVu) {
        [UIView animateWithDuration:0.5 animations:^{
            containerVu.frame = CGRectMake(Screen_Width, 0, Screen_Width, Screen_Height/8*7);
            self.playerView.frame = CGRectMake(0, 0, Screen_Width, Screen_Height/8*7);
        } completion:^(BOOL finished) {
            for (int i = 0 ; i < 5; i ++) {
                CustomBtn *btn = bottomBtnArray[i];
                btn.userInteractionEnabled = YES;
            }
            CustomBtn *btn = bottomBtnArray[currentBottomBtnIndex];
            btn.selected = NO;
            btn = nil;
            [containerVu removeFromSuperview];
            containerVu = nil;
        }];
    }
    //课程目录处理
    lessonVu = [[UIView alloc] initWithFrame:CGRectMake(0, Screen_Height, Screen_Width, Screen_Height/8)];
    lessonVu.backgroundColor = [UIColor colorWithRed:67/255.0 green:67/255.0 blue:67/255.0 alpha:1];
    [self.view addSubview:lessonVu];
    [UIView animateWithDuration:0.3 animations:^{
        lessonVu.frame = CGRectMake(0, Screen_Height/8*7, Screen_Width, Screen_Height/8);
    }];
    clearBtn = [[UIButton alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [clearBtn addTarget:self action:@selector(disappear) forControlEvents:UIControlEventTouchUpInside];
    [self.view insertSubview:clearBtn belowSubview:self.bottomTool];
    
    UIButton *lessonBtn = [[UIButton alloc] initWithFrame:CGRectMake(Screen_Width/30, Screen_Height/8/2*0.6, Screen_Width/7, Screen_Height/8/2)];
    [lessonBtn setTitle:@"我的视频" forState:UIControlStateNormal];
    [lessonBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    lessonBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    lessonBtn.layer.borderWidth = 1;
    lessonBtn.layer.cornerRadius = 5;
    [lessonVu addSubview:lessonBtn];
    
    UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(Screen_Width*0.9, Screen_Height/8/4*3/2, Screen_Height/8/4, Screen_Height/8/4)];
    [backBtn setBackgroundImage:[UIImage imageNamed:@"lesson_list_cancle.png"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(disappear) forControlEvents:UIControlEventTouchUpInside];
    [lessonVu addSubview:backBtn];
}

- (void)disappear{
    //课程操作视图消失动画;
    CustomBtn *btn = bottomBtnArray[currentBottomBtnIndex];
    btn.selected = NO;
    btn = nil;
    currentBottomBtnIndex = -1;
    clearBtn.enabled = NO;
    [UIView animateWithDuration:0.3 animations:^{
        lessonVu.frame = CGRectMake(0, Screen_Height, Screen_Width, Screen_Height/8);
    } completion:^(BOOL finished) {
        for (int i = 0 ; i < 5; i ++) {
            CustomBtn *btn = bottomBtnArray[i];
            btn.userInteractionEnabled = YES;
        }
        [clearBtn removeFromSuperview];
        clearBtn = nil;
        [lessonVu removeFromSuperview];
        lessonVu = nil;
    }];
}

#pragma mark 课程

#pragma mark -

#pragma mark 互动


- (void)interaction{
    //互动处理
    currentTableViewIndex = 1;
    if (containerVu) {
        [UIView animateWithDuration:0.5 animations:^{
            containerVu.frame = CGRectMake(Screen_Width, 0, Screen_Width, Screen_Height/8*7);
        } completion:^(BOOL finished) {
            [containerVu removeFromSuperview];
            containerVu = nil;
            [self dealData:@"front_comment!listComment.action"];
        }];
    } else {
        [UIView animateWithDuration:0.3 animations:^{
            self.playerView.frame = CGRectMake(0, 0, Screen_Width/3*2, Screen_Height*0.6);
        } completion:^(BOOL finished) {
            [self dealData:@"front_comment!listComment.action"];
        }];
    }
}


#pragma mark 互动
#pragma mark -
#pragma mark 提问

- (void)question{
    //提问处理
    currentTableViewIndex = 2;
    if (containerVu) {
        [UIView animateWithDuration:0.5 animations:^{
            containerVu.frame = CGRectMake(Screen_Width, 0, Screen_Width, Screen_Height/8*7);
        } completion:^(BOOL finished) {
            [containerVu removeFromSuperview];
            containerVu = nil;
             [self dealData:@"front_video!questionList.action"];
        }];
    } else {
        [UIView animateWithDuration:0.3 animations:^{
            self.playerView.frame = CGRectMake(0, 0, Screen_Width/3*2, Screen_Height*0.6);
        } completion:^(BOOL finished) {
             [self dealData:@"front_video!questionList.action"];
        }];
    }
}


#pragma mark 提问
#pragma mark - 
#pragma mark 笔记

- (void)rememberNote{
    //记笔记处理
    if (containerVu) {
        [UIView animateWithDuration:0.5 animations:^{
            containerVu.frame = CGRectMake(Screen_Width, 0, Screen_Width, Screen_Height/8*7);
        } completion:^(BOOL finished) {
            [containerVu removeFromSuperview];
            containerVu = nil;
            [self dealRememberNote];
        }];
    } else {
        [UIView animateWithDuration:0.3 animations:^{
            self.playerView.frame = CGRectMake(0, 0, Screen_Width/3*2, Screen_Height*0.6);
        } completion:^(BOOL finished) {
            [self dealRememberNote];
        }];
    }
    
}

- (void)dealRememberNote{
    [self createContainerVu];
    titleLabel.text = customBtnNames[currentBottomBtnIndex];
    [UIView animateWithDuration:0.5 animations:^{
        containerVu.frame = CGRectMake(Screen_Width/3*2, 0, Screen_Width, Screen_Height/8*7);
    } completion:^(BOOL finished) {
        for (int i = 0 ; i < 5; i ++) {
            CustomBtn *btn = bottomBtnArray[i];
            btn.userInteractionEnabled = YES;
        }
    }];
    UIView *backVu = [[UIView alloc] initWithFrame:CGRectMake(0, Screen_Height/8*7*0.1, Screen_Width/3, Screen_Height/8*7*0.9)];
    backVu.backgroundColor = [UIColor colorWithRed:56/255.0 green:56/255.0 blue:56/255.0 alpha:1];
    [containerVu addSubview:backVu];
    noteText = [[UITextView alloc] initWithFrame:CGRectMake(Screen_Width/3*0.1, Screen_Height/8*7*0.9*0.15, Screen_Width/3*0.8, Screen_Height/8*7*0.9*0.5)];
    [containerVu addSubview:noteText];
    UIButton *cancel = [[UIButton alloc] initWithFrame:CGRectMake(Screen_Width/3*0.1, Screen_Height/8*7*0.9*0.7, Screen_Width/3*0.35, Screen_Height/8*7*0.9*0.5*0.1)];
    [cancel setTitle:@"取消" forState:UIControlStateNormal];
    [cancel setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    cancel.layer.borderColor = [UIColor whiteColor].CGColor;
    cancel.layer.borderWidth = 1;
    [cancel addTarget:self action:@selector(rightToolBtn:) forControlEvents:UIControlEventTouchUpInside];
    [containerVu addSubview:cancel];
    UIButton *confirm = [[UIButton alloc] initWithFrame:CGRectMake(Screen_Width/3*0.5, Screen_Height/8*7*0.9*0.7, Screen_Width/3*0.35, Screen_Height/8*7*0.9*0.5*0.1)];
    [confirm setTitle:@"确定" forState:UIControlStateNormal];
    [confirm setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    confirm.layer.borderColor = [UIColor whiteColor].CGColor;
    confirm.layer.borderWidth = 1;
    [confirm addTarget:self action:@selector(commitNote:) forControlEvents:UIControlEventTouchUpInside];
    [containerVu addSubview:confirm];
    UIButton *voice = [[UIButton alloc] initWithFrame:CGRectMake(Screen_Width/3*0.8, Screen_Height/8*7*0.025, Screen_Height/8*7*0.025, Screen_Height/8*7*0.05)];
    [voice setBackgroundImage:[UIImage imageNamed:@"microphone.png"] forState:UIControlStateNormal];
    [voice setBackgroundImage:[UIImage imageNamed:@"microphone_s.png"] forState:UIControlStateHighlighted];
    [voice addTarget:self action:@selector(saveVoice:) forControlEvents:UIControlEventTouchUpInside];
    [containerVu addSubview:voice];
}

- (void)saveVoice:(UIButton *)sender{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"正在录音中..\n" delegate:self cancelButtonTitle:@"放弃" otherButtonTitles:@"保存", nil];
    alert.tag = 202;
    [alert show];
}

- (void)commitNote:(UIButton *)sender{
    if (noteText.text.length == 0) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"不能保存空内容" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        [alert show];
    } else {
        //提交
        [[NetWorkTools sharedTools] requestMethod:POST URL:sid(url(@"front_video!addNote.action")) parameters:@{@"msg":noteText.text,@"resourceId":self.playerListIDArray[playIndex],@"style":@"course",@"timePoint":@(14)} finish:^(id responseObject, NSError *error) {
            if ([responseObject[@"status"] intValue] == 1) {
                UIAlertView *alertVu = [[UIAlertView alloc] initWithTitle:@"提示" message:responseObject[@"data"] delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
                [alertVu show];
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [alertVu dismissWithClickedButtonIndex:0 animated:YES];
                    [self rightToolBtn:nil];
                });
            }
        }];
    }
}

- (void)dealVoice{
    
}

- (void)back{
    //返回处理
    UIAlertView *backAlert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"退出教学视频" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [backAlert show];
    for (int i = 0 ; i < 5; i ++) {
        CustomBtn *btn = bottomBtnArray[i];
        btn.userInteractionEnabled = YES;
    }
}




#pragma mark - UITableViewDataSource,UITableViewDelegate

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.tag == 301) {
        FriendInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"friendInfo" forIndexPath:indexPath];
        [cell.imageVu sd_setImageWithURL:[NSURL URLWithString:url(rightDataSource[indexPath.row][@"head"])] placeholderImage:nil options:SDWebImageProgressiveDownload];
        cell.name.text = rightDataSource[indexPath.row][@"username"];
        cell.backgroundColor = [UIColor colorWithRed:56/255.0 green:56/255.0 blue:56/255.0 alpha:1];
        cell.name.textColor = [UIColor whiteColor];
        return cell;
    }
    if (currentTableViewIndex == 1) {
        InfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"info" forIndexPath:indexPath];
        [cell.headerImage sd_setImageWithURL:[NSURL URLWithString:url(interactionArray[indexPath.row][@"head"])] placeholderImage:nil options:SDWebImageProgressiveDownload];
        cell.headerName.text = interactionArray[indexPath.row][@"name"];
        cell.content.text = interactionArray[indexPath.row][@"content"];
        cell.time.text = interactionArray[indexPath.row][@"time"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    } else if(currentTableViewIndex == 2){
        QuestionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"question" forIndexPath:indexPath];
        [cell.headerImage sd_setImageWithURL:[NSURL URLWithString:url(interactionArray[indexPath.row][@"userPic"])] placeholderImage:nil options:SDWebImageProgressiveDownload];
        cell.headerName.text = interactionArray[indexPath.row][@"userName"];
        cell.content.text = interactionArray[indexPath.row][@"msg"];
        cell.scan.text = [@"浏览:" stringByAppendingString:[interactionArray[indexPath.row][@"lookNum"] stringValue]];
        cell.answer.text = [@"回答:" stringByAppendingString:[interactionArray[indexPath.row][@"answerNum"] stringValue]];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    if (tableView.tag == 302) {
        DetailInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"detail" forIndexPath:indexPath];
        cell.backgroundColor = [UIColor colorWithRed:67/255.0 green:67/255.0 blue:67/255.0 alpha:1];
        [cell.titleBtn setTitle:detailInfoArray[indexPath.row][@"lname"] forState:UIControlStateNormal];
        cell.name.text = [@"讲师: " stringByAppendingString:detailInfoArray[indexPath.row][@"teacher"]];
        cell.time.text = [[@"共" stringByAppendingString:[detailInfoArray[indexPath.row][@"countLession"] stringValue]] stringByAppendingString:@"课时"];
        cell.student.text = [[detailInfoArray[indexPath.row][@"student"] stringValue]stringByAppendingString:@"在学习"];
        cell.star.text = @"😂😂😂😂😂";
        cell.discuss.text = [[detailInfoArray[indexPath.row][@"discuss"] stringValue] stringByAppendingString:@"评价"];
        return cell;
    }
    return [UITableViewCell new];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView.tag == 300) {
        return interactionArray.count;
    } else if (tableView.tag == 301) {
        return rightDataSource.count;
    }
    if (tableView.tag == 302) {
        return detailInfoArray.count;
    }
    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView.tag == 302) {
        return Screen_Height/8*7*0.9*0.5/2;
    }
    if (tableView.tag == 301 && currentRightIndex == 13) {
        return 100;
    }
    return Screen_Height/8*7*0.8*0.28;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (tableView.tag == 301 && currentRightIndex == 13) {
        detailContainerVu = [[UIView alloc] initWithFrame:CGRectMake(Screen_Width/3, 0, Screen_Width/3, Screen_Height/8*7)];
        detailContainerVu.backgroundColor = [UIColor darkGrayColor];
        UIView *headerVu = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width/3, Screen_Height/8*7*0.1)];
        headerVu.backgroundColor = [UIColor darkGrayColor];
        [detailContainerVu addSubview:headerVu];
        titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, Screen_Width/3, Screen_Height/8*7*0.1)];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.font = [UIFont boldSystemFontOfSize:23];
        titleLabel.textColor = [UIColor whiteColor];
        titleLabel.text = rightDataSource[indexPath.row][@"username"];
        [detailContainerVu addSubview:titleLabel];
        UIButton *rightToolBackBtn = [[UIButton alloc] initWithFrame:CGRectMake(Screen_Height/8*7*0.1/2/2/2, Screen_Height/8*7*0.1/2/2/2, Screen_Height/8*7*0.1/2, Screen_Height/8*7*0.1/2)];
        [rightToolBackBtn addTarget:self action:@selector(detailBackBtn:) forControlEvents:UIControlEventTouchUpInside];
        [rightToolBackBtn setBackgroundImage:[UIImage imageNamed:@"lesson_detail_back.png"] forState:UIControlStateNormal];
        [detailContainerVu addSubview:rightToolBackBtn];
        [containerVu addSubview:detailContainerVu];
        [UIView animateWithDuration:0.3 animations:^{
            friendContainerVu.frame = CGRectMake(-Screen_Width/3, 0, Screen_Width/3, Screen_Height/8*7);
            detailContainerVu.frame = CGRectMake(0, 0, Screen_Width/3, Screen_Height/8*7);
        }];
        
        UIView *topVu = [[UIView alloc] initWithFrame:CGRectMake(0, Screen_Height/8*7*0.1, Screen_Width/3, Screen_Height/8*7*0.9*0.5)];
        topVu.backgroundColor = [UIColor colorWithRed:67/255.0 green:67/255.0 blue:67/255.0 alpha:1];
        [detailContainerVu addSubview:topVu];
        UIImageView *headImageView = [[UIImageView alloc] initWithFrame:CGRectMake(Screen_Width/3/4*0.35, Screen_Width/3/4*0.35, Screen_Width/3/4, Screen_Width/3/4)];
        [topVu addSubview:headImageView];
        UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(Screen_Width/3/4*1.5, Screen_Width/3/4*0.35, Screen_Width/3*0.7, Screen_Width/3*0.125)];
        name.textColor = [UIColor whiteColor];
        name.font = [UIFont systemFontOfSize:22];
        [topVu addSubview:name];
        UILabel *phone = [[UILabel alloc] initWithFrame:CGRectMake(Screen_Width/3/4*1.5, Screen_Width/3/4*0.35+Screen_Width/3*0.125, Screen_Width/3*0.7, Screen_Width/3*0.125)];
        phone.textColor = [UIColor whiteColor];
        phone.font = [UIFont systemFontOfSize:22];
        [topVu addSubview:phone];
        UILabel *area = [[UILabel alloc] initWithFrame:CGRectMake(Screen_Width/3/4*0.35, Screen_Width/3/4*0.4+Screen_Width/3/4, Screen_Width/3*0.7, Screen_Width/3*0.125)];
        area.font = [UIFont systemFontOfSize:22];
        area.textColor = [UIColor whiteColor];
        [topVu addSubview:area];
        UILabel *company = [[UILabel alloc] initWithFrame:CGRectMake(Screen_Width/3/4*0.35, Screen_Width/3/4*0.4+Screen_Width/3/4+Screen_Width/3*0.125, Screen_Width/3*0.7, Screen_Width/3*0.125)];
        company.textColor = [UIColor whiteColor];
        company.font = [UIFont systemFontOfSize:22];
        [topVu addSubview:company];
        UIButton *addFriend = [[UIButton alloc] initWithFrame:CGRectMake(Screen_Width/3*0.1, Screen_Height/8*7*0.9*0.5*0.7, Screen_Width/3*0.8 , Screen_Width/3/4*0.4)];
        [addFriend setTitle:@"加为好友" forState:UIControlStateNormal];
        [addFriend setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        addFriend.layer.borderColor = [UIColor whiteColor].CGColor;
        addFriend.layer.borderWidth = 1;
        [topVu addSubview:addFriend];
        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, Screen_Height/8*7*0.9*0.5*0.9, Screen_Width/3, 1)];
        line.backgroundColor = [UIColor blackColor];
        [topVu addSubview:line];
        UILabel *alert = [[UILabel alloc] initWithFrame:CGRectMake(Screen_Width/3*0.05, Screen_Height/8*7*0.9*0.5*0.8, Screen_Width/3, Screen_Height/8*7*0.15)];
        alert.text = @"已参加的课程";
        alert.textColor = [UIColor whiteColor];
        [topVu addSubview:alert];
        UITableView *detailTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, Screen_Height/8*7*0.9*0.5+Screen_Height/8*7*0.1, Screen_Width/3, Screen_Height/8*7*0.9*0.5) style:UITableViewStylePlain];
        detailTableView.tag = 302;
        [detailTableView registerClass:[DetailInfoTableViewCell class] forCellReuseIdentifier:@"detail"];
        detailTableView.tableFooterView = [UIView new];
        detailTableView.backgroundColor = [UIColor colorWithRed:67/255.0 green:67/255.0 blue:67/255.0 alpha:1];
        detailTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
            [[NetWorkTools sharedTools] requestMethod:POST URL:sid(url(@"front_video!loadStudentCourse.action")) parameters:@{@"token":[[NSUserDefaults standardUserDefaults] objectForKey:@"token"],@"id":rightDataSource[indexPath.row][@"id"],@"pageNum":@(1),@"pageSize":@(10)} finish:^(id responseObject, NSError *error) {
                if ([responseObject[@"status"] intValue] == 104) {
                    NSLog(@"重新登陆");
                } else if ([responseObject[@"status"] intValue] == 1){
                    [headImageView sd_setImageWithURL:[NSURL URLWithString:url(responseObject[@"data"][@"userinfo"][@"head"])] placeholderImage:nil options:SDWebImageProgressiveDownload];
                    name.text = [@"用户昵称: " stringByAppendingString:responseObject[@"data"][@"userinfo"][@"username"]];
                    phone.text = [@"手机号码: " stringByAppendingString:responseObject[@"data"][@"userinfo"][@"phone"]];
                    area.text = [@"地区: " stringByAppendingString:responseObject[@"data"][@"userinfo"][@"address"]];
                    NSArray * companyArray = responseObject[@"data"][@"userinfo"][@"company"];
                    if (companyArray.count == 0) {
                        company.text = @"公司名称:";
                    } else {
                        company.text = [@"公司名称: " stringByAppendingString:responseObject[@"data"][@"userinfo"][@"company"][0][@"company"]];
                    }
                    [detailTableView.mj_header endRefreshing];
                    detailInfoArray = responseObject[@"data"][@"lesson"];
                    detailTableView.dataSource = self;
                    detailTableView.delegate = self;
                    
                }
            }];
        }];
        [detailTableView.mj_header beginRefreshing];
        detailTableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
            [detailTableView.mj_footer endRefreshing];
        }];
        [detailContainerVu addSubview:detailTableView];
    
    }
}

#pragma mark - Hidden Status
- (BOOL)prefersStatusBarHidden{
    return YES;
}

#pragma mark - UIAlertViewDelegate

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (alertView.tag == 200) {
        if (buttonIndex == 0) {
            [self.playerView.player seekToTime:kCMTimeZero completionHandler:^(BOOL finished) {
                [self.slider setValue:0 animated:YES];
                self.playerBtn.selected = NO;
            }];
        } else if (buttonIndex == 1){
            //跳下一课程
            playIndex ++;
            [playerItem removeObserver:self forKeyPath:@"status" context:nil];
            [self.playerView.player removeTimeObserver:self.playbackTimeObserver];
            [[NSNotificationCenter defaultCenter] removeObserver:self];
            playerItem = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:self.playerListArray[playIndex]]];
            [playerItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil];
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem];
            [self.playerView.player replaceCurrentItemWithPlayerItem:playerItem];
        }
        
    } else if (alertView.tag == 201){
        if (buttonIndex == 0) {
            [self.playerView.player seekToTime:kCMTimeZero completionHandler:^(BOOL finished) {
                [self.slider setValue:0 animated:YES];
                self.playerBtn.selected = NO;
            }];
        } else {
            [self.playerView.player pause];
            [self dismissViewControllerAnimated:YES completion:nil];
        }
        
    } else if (alertView.tag == 202) {
        if (buttonIndex == 1) {
            [self dealVoice];
        }
    } else {
        if (buttonIndex == 0) {
            CustomBtn *btn = bottomBtnArray[currentBottomBtnIndex];
            btn.selected = NO;
            btn = nil;
            currentBottomBtnIndex = -1;
        } else if (buttonIndex == 1){
            [self.playerView.player pause];
            [self dismissViewControllerAnimated:YES completion:nil];
        }
    }
}

#pragma mark - Getter

- (UIView *)rightTool{
    if (!_rightTool) {
        _rightTool = [[UIView alloc] initWithFrame:CGRectMake(Screen_Width/8*7, Screen_Height/2/2, Screen_Width/8, Screen_Height/2)];
        _rightTool.backgroundColor = [UIColor grayColor];
    }
    return _rightTool;
}

- (UIView *)bottomTool{
    if (!_bottomTool) {
        _bottomTool = [[UIView alloc] initWithFrame:CGRectMake(0, Screen_Height/8*7, Screen_Width, Screen_Height/8)];
        _bottomTool.backgroundColor = [UIColor darkGrayColor];
    }
    return _bottomTool;
}

- (UILabel *)timeLabel{
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(Screen_Width/3*2/3*2, Screen_Height/8*0.1, Screen_Width/3*2/3-Screen_Width/3*2/30, Screen_Height/8/3)];
        _timeLabel.textAlignment = NSTextAlignmentRight;
        _timeLabel.text = @"00:00:00/00:00:00";
        _timeLabel.textColor = [UIColor whiteColor];
    }
    return _timeLabel;
}

- (NSDateFormatter *)dateFormatter {
    if (!_dateFormatter) {
        _dateFormatter = [[NSDateFormatter alloc] init];
    }
    return _dateFormatter;
}


@end
